/*
 * Created on Oct 3, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.vectrics.recruiter.struts.admin;

import org.apache.ecs.html.A;
import org.vectrics.common.html.BorderTable;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Row;
import org.vectrics.common.html.Table;
import org.vectrics.common.html.TextHelper;
import org.vectrics.struts.VectricsTagSupport;
import org.vectrics.user.Person;

/**
 * @author mmoore
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class UserCredentialsTag extends VectricsTagSupport {

	private static final long serialVersionUID = -507682861383593357L;
	
	private final String HREF_LOGOFF = "/logoff.do";
	/* (non-Javadoc)
	 * @see org.vectrics.struts.VectricsTagSupport#makeStartTag()
	 */
	protected String makeStartTag() {
		Table mainTable = new BorderTable();
		Row mainRow = mainTable.addRow();
		Cell mainCell = mainRow.addCell();
		
		Table table = new Table();
		table.setCellPadding(0);
		table.setCellSpacing(0);
		mainCell.addElement(table);
		Row row = table.addRow();
		Cell cell = row.addCell();
		
		Person person = this.getAuthPerson();
		if (person == null) {
			cell.addElement(TextHelper.getFont("subFont", this.getPhrase("phrase.no.user.logged.in")));
		} else {
			cell.addElement(TextHelper.getFont("subFont", person.getName()));
			cell = row.addCell();
			cell.addElement("&nbsp;");
			
			cell = row.addCell();
			A logOffLink = new A();
			logOffLink.setHref(this.getContextPath() + HREF_LOGOFF);
			logOffLink.setClass("subLink");
			logOffLink.addElement(this.getPhrase("phrase.logoff"));
			cell.addElement(logOffLink);
			
		}
		return mainTable.toString();
	}

}
